package top.heue.text;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import android.widget.GridView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import java.util.List;

import top.heue.text.adapter.ContentListAdapter;
import top.heue.text.bean.ContentBean;
import top.heue.text.bean.ContentListBean;
import top.heue.text.sql.SQLite;
import top.heue.text.util.ListUtil;

public class ContentActivity extends AppCompatActivity {
    public final static String ContentId = "ContentId";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_content);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        GridView view = findViewById(R.id.grid_content);
        int w = view.getRequestedColumnWidth();
        Log.i("Mine", String.valueOf(w));
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager windowManager = this.getWindowManager();
        windowManager.getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;
        w = width / w;
        String id = getIntent().getStringExtra(ContentId);
        SQLite sqLite = new SQLite(this);
        ContentBean contentBean = sqLite.query(id);
        setTitle(contentBean.title);
        String str = contentBean.content;
        List<ContentListBean> l = ListUtil.listFormat(str, w);
        ContentListAdapter a = new ContentListAdapter(this, l);
        view.setAdapter(a);

    }
}